﻿using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using WCFCarservice;

namespace WCFSelfHosting
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a URI to serve as the base address

            ServiceHost host = new ServiceHost(typeof(CarService));

            //Add a service endpoint
            Uri httpUrl = new Uri("http://localhost:7070/OurServices/CarService");
            host.AddServiceEndpoint(typeof(WCFCarservice.ICar)
                                    , new BasicHttpBinding(), httpUrl);

            Uri tcpUrl = new Uri("net.tcp://localhost:8080/OurServices/CarService");
            host.AddServiceEndpoint(typeof(ICar)
                                    , new NetTcpBinding(), tcpUrl);

            //Enable metadata exchange
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.HttpGetUrl = httpUrl;
            host.Description.Behaviors.Add(smb);


            host.Open();
            Console.WriteLine("Service Started! Press any key to stop the service...");
            Console.Read();
            host.Close();

        }
    }
}
